package com.miszczu.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.miszczu.model.Messagesreceived;
import com.miszczu.model.Users;
import com.miszczu.utils.CustomHibernateSupport;

@Repository
public class MessagesDaoImpl extends CustomHibernateSupport implements MessagesDao {

	public List<Messagesreceived> getReceivedMessages(Users user) {
		
		List<Messagesreceived> messagesReceived = getSession().createQuery("from Messagesreceived as mr where mr.users = :user")
		.setEntity("user", user)
		.list();
		
		return messagesReceived;
		
	}

	public Messagesreceived getOneReceivedMessage(Integer id) {

		return (Messagesreceived) getHibernateTemplate().get(Messagesreceived.class, id);
	}

	public void deleteReceivedMessage(Messagesreceived message) {
		
		getHibernateTemplate().delete(message);
		
	}

}
